<!DOCTYPE html>
<html  lang="zh-CN" >
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, maximum-scale=5, viewport-fit=cover">
    <title>Prometheus部署文档 | 学为我用</title>
    <meta name="description" content="Prometheus部署 Spark作业通过Prometheus监控 Flink作业通过Prometheus监控  Prometheus部署首先下载prometheus包 1wget https:&#x2F;&#x2F;github.com&#x2F;prometheus&#x2F;prometheus&#x2F;releases&#x2F;download&#x2F;v2.19.3&#x2F;prometheus-2.19.3.linux-amd64.tar.gz  解压">
<meta property="og:type" content="article">
<meta property="og:title" content="Prometheus部署文档">
<meta property="og:url" content="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/03/202008031448-promethues-deploy/index.html">
<meta property="og:site_name" content="学为我用">
<meta property="og:description" content="Prometheus部署 Spark作业通过Prometheus监控 Flink作业通过Prometheus监控  Prometheus部署首先下载prometheus包 1wget https:&#x2F;&#x2F;github.com&#x2F;prometheus&#x2F;prometheus&#x2F;releases&#x2F;download&#x2F;v2.19.3&#x2F;prometheus-2.19.3.linux-amd64.tar.gz  解压">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/03/202008031448-promethues-deploy/s_1.png">
<meta property="og:image" content="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/03/202008031448-promethues-deploy/s_5.png">
<meta property="og:image" content="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/03/202008031448-promethues-deploy/s_6.png">
<meta property="og:image" content="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/03/202008031448-promethues-deploy/s_2.png">
<meta property="og:image" content="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/03/202008031448-promethues-deploy/s_3.png">
<meta property="og:image" content="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/03/202008031448-promethues-deploy/s_4.png">
<meta property="article:published_time" content="2020-08-03T06:48:41.000Z">
<meta property="article:modified_time" content="2020-09-10T03:25:01.981Z">
<meta property="article:author" content="章瑱彬">
<meta property="article:tag" content="大数据">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/03/202008031448-promethues-deploy/s_1.png">

    
    <link rel="icon" href="/zzbomb/images/favicon_128.ico" type="image/x-icon">

    
<link rel="stylesheet" href="/zzbomb/css/common.min.css">



    
    
    
    
        <link href="//cdn.jsdelivr.net/npm/lightgallery.js@1.1.3/dist/css/lightgallery.min.css" rel="stylesheet">
    
    
    
<link rel="stylesheet" href="/zzbomb/css/iconfont.min.css">

    
<meta name="generator" content="Hexo 4.2.1"></head>

    <body>
        <header class="header header-fixture">
    <div class="profile-search-wrap flex sm:block">
        
        
        <div class="profile sm:text-center md:px-1 lg:px-3 sm:pb-4 sm:pt-6">
            <a id="avatar" role="link" href="https://gitee.com/123zhangzhenbin" class="inline-block lg:w-16 lg:h-16 w-8 h-8 m-2" target="_blank" rel="noopener" rel="noreferrer" >
                <img src="/zzbomb/images/g.jpg" class="rounded-full" alt="avatar">
            </a>
            <h2 id="name" class="hidden lg:block">ZZB</h2>
            <h3 id="title" class="hidden xl:block">Java，大数据，人工智能，区块链</h3>
            
            <small id="location" class="hidden lg:block">
                <i class="iconfont icon-map-icon"></i>
                DongGuan, China
            </small>
            
        </div>
        
        
<div class="search flex-1 flex lg:inline-block sm:hidden lg:px-4 lg:mt-2 lg:mb-4 lg:w-full">
    <form id="search-form" class="my-auto flex-1 lg:border lg:border-solid lg:border-gray-200">
        <div class="input-group table bg-gray-100 lg:bg-white w-full">
            <input id="search-input" type="text" placeholder="搜索" class="inline-block w-full bg-gray-100 lg:bg-white">
            <span class="table-cell">
                <button name="search tigger button" disabled>
                    <i class="iconfont icon-search m-2"></i>
                </button>
            </span>
        </div>
    </form>
        
<script id="search-teamplate" type="text/html" data-path="/zzbomb/content.json">
    <div>
        <div class="search-header bg-gray-400">
            <input id="actual-search-input" model="keyword" ref="input" class="inline-block w-full h-10 px-2 py-1" placeholder="搜索" type="text">
        </div>
        <div class="search-result bg-gray-200">
            {{#each searchPosts}}
            <a href="/{{ path }}" class="result-item block px-2 pb-3 mb-1 pt-1 hover:bg-indigo-100">
                <i class="iconfont icon-file"></i>
                <h1 class="result-title inline font-medium text-lg">{{ title }}</h1>
                <p class="result-content text-gray-600 text-sm">{{{ text }}}</p>
            </a>
            {{/each}}
        </div>
    </div>
</script>

</div>


        <button name="menu toogle button" id="menu-toggle-btn" class="block sm:hidden p-3" role="button" aria-expanded="false">
            <i class="iconfont icon-hamburger"></i>
        </button>
    </div>
    <nav id="menu-nav" class="hidden sm:flex flex-col">
        
        
            <div class="menu-item menu-home" role="menuitem">
                <a href="/zzbomb/.">
                    <i class="iconfont icon-home" aria-hidden="true"></i>
                    <span class="menu-title">首页</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-archives" role="menuitem">
                <a href="/zzbomb/archives">
                    <i class="iconfont icon-archive" aria-hidden="true"></i>
                    <span class="menu-title">归档</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-categories" role="menuitem">
                <a href="/zzbomb/categories">
                    <i class="iconfont icon-folder" aria-hidden="true"></i>
                    <span class="menu-title">分类</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-tags" role="menuitem">
                <a href="/zzbomb/tags">
                    <i class="iconfont icon-tag" aria-hidden="true"></i>
                    <span class="menu-title">标签</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-repository" role="menuitem">
                <a href="/zzbomb/repository">
                    <i class="iconfont icon-project" aria-hidden="true"></i>
                    <span class="menu-title">项目</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-links" role="menuitem">
                <a href="/zzbomb/links">
                    <i class="iconfont icon-friend" aria-hidden="true"></i>
                    <span class="menu-title">友链</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-about" role="menuitem">
                <a href="/zzbomb/about">
                    <i class="iconfont icon-cup" aria-hidden="true"></i>
                    <span class="menu-title">关于</span>
                </a>
            </div>
        
        
<div class="social-links flex sm:flex-col lg:hidden mt-5">
    
        <span class="social-item text-center">
            <a href="https://gitee.com/123zhangzhenbin" target="_blank" rel="noopener">
                <i class="iconfont social-icon icon-github"></i>
                <span class="menu-title hidden lg:inline">menu.github</span>
            </a>
        </span>
    
</div>


    </nav>
</header>

        <section class="main-section">
            
    <main class="flex-1 px-4 py-12 md:px-5 lg:px-8 lg:py-4 relative min-h-screen">
    

    <article class="content article article-archives article-type-list" itemscope="">
        <header class="article-header">
            
    
        <h1 class="article-title text-lg" itemprop="name">
            Prometheus部署文档
        </h1>
    



            <p class="article-meta mb-3 text-xs">
                <span class="article-date">
    <i class="iconfont icon-calendar-check"></i>
	<a href="/zzbomb/2020/08/03/202008031448-promethues-deploy/" class="article-date">
	  <time datetime="2020-08-03T06:48:41.000Z" itemprop="datePublished">8月 3</time>
	</a>
</span>

                

                
    <span class="article-tags">
    <i class="iconfont icon-tag"></i>
    <a class="article-tag-link" href="/zzbomb/tags/%E5%A4%A7%E6%95%B0%E6%8D%AE/" rel="tag">大数据</a>
  </span>


                <span class="_partial/post-comment"><i class="icon icon-comment"></i>
                    <a href="/zzbomb/2020/08/03/202008031448-promethues-deploy/#comments" class="article-comment-link">
                        评论
                    </a>
                </span>
                

            </p>
        </header>
        <div class="marked-body article-body">
            <ul>
<li><a href="#prometheus%E9%83%A8%E7%BD%B2">Prometheus部署</a></li>
<li><a href="#spark%E4%BD%9C%E4%B8%9A%E9%80%9A%E8%BF%87prometheus%E7%9B%91%E6%8E%A7">Spark作业通过Prometheus监控</a></li>
<li><a href="#flink%E4%BD%9C%E4%B8%9A%E9%80%9A%E8%BF%87prometheus%E7%9B%91%E6%8E%A7">Flink作业通过Prometheus监控</a></li>
</ul>
<h2 id="Prometheus部署"><a href="#Prometheus部署" class="headerlink" title="Prometheus部署"></a>Prometheus部署</h2><p>首先下载prometheus包</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">wget https:<span class="hljs-regexp">//gi</span>thub.com<span class="hljs-regexp">/prometheus/</span>prometheus<span class="hljs-regexp">/releases/</span>download<span class="hljs-regexp">/v2.19.3/</span>prometheus-<span class="hljs-number">2.19</span>.<span class="hljs-number">3</span>.linux-amd64.tar.gz<br></code></pre></td></tr></table></figure>

<p>解压</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-selector-tag">tar</span> <span class="hljs-selector-tag">-zxvf</span> <span class="hljs-selector-tag">prometheus-2</span><span class="hljs-selector-class">.19</span><span class="hljs-selector-class">.3</span><span class="hljs-selector-class">.linux-amd64</span><span class="hljs-selector-class">.tar</span><span class="hljs-selector-class">.gz</span><br></code></pre></td></tr></table></figure>

<p>此时如果不做任何配置，会自动开启一个监控自身的指标监控，我们先直接启动程序试试</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs angelscript">cd prometheus<span class="hljs-number">-2.19</span><span class="hljs-number">.3</span>.linux-amd64<br>nohup prometheus --config.file=prometheus.yml --web.listen-address=:<span class="hljs-number">9191</span> &gt;/dev/<span class="hljs-literal">null</span> <span class="hljs-number">2</span>&gt;&amp;<span class="hljs-number">1</span> &amp;<br></code></pre></td></tr></table></figure>
<p>这里指的是指定配置文件prometheus.yml，使用9191端口开启web程序</p>
<p>通过浏览器，就可以访问到prometheus的web界面了。<br><img src="/zzbomb/2020/08/03/202008031448-promethues-deploy/s_1.png" alt="s_1"><br>在输入框输入prometheus_build_info，然后点击Execute，看看当前版本信息。</p>
<h2 id="Spark作业通过Prometheus监控"><a href="#Spark作业通过Prometheus监控" class="headerlink" title="Spark作业通过Prometheus监控"></a>Spark作业通过Prometheus监控</h2><p>spark的metric中实现了graphite_exporter的插件，所以这里我们可以通过推送到graphite中，然后配置Prometheus从graphite中拉取指标数据</p>
<p>首先需要下载graphite_exporter</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs awk">wget https:<span class="hljs-regexp">//gi</span>thub.com<span class="hljs-regexp">/prometheus/g</span>raphite_exporter<span class="hljs-regexp">/releases/</span>download<span class="hljs-regexp">/v0.9.0/g</span>raphite_exporter-<span class="hljs-number">0.9</span>.<span class="hljs-number">0</span>.linux-amd64.tar.gz<br></code></pre></td></tr></table></figure>

<p>解压</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs bash">tar -zxvf graphite_exporter-0.9.0.linux-amd64.tar.gz<br></code></pre></td></tr></table></figure>

<p>添加spark作业监控配置</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs css"><span class="hljs-selector-tag">cd</span> <span class="hljs-selector-tag">graphite_exporter-0</span><span class="hljs-selector-class">.9</span><span class="hljs-selector-class">.0</span><span class="hljs-selector-class">.linux-amd64</span><br><span class="hljs-selector-tag">touch</span> <span class="hljs-selector-tag">spark_mapping</span><br><span class="hljs-selector-tag">vi</span> <span class="hljs-selector-tag">spark_mapping</span><br></code></pre></td></tr></table></figure>
<p>内容如下</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br></pre></td><td class="code"><pre><code class="hljs yaml"><span class="hljs-attr">mappings:</span><br><span class="hljs-bullet">-</span> <span class="hljs-attr">match:</span> <span class="hljs-string">'*.*.executor.filesystem.*.*'</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">spark_app_filesystem_usage</span><br>  <span class="hljs-attr">labels:</span><br>    <span class="hljs-attr">application:</span> <span class="hljs-string">$1</span><br>    <span class="hljs-attr">executor_id:</span> <span class="hljs-string">$2</span><br>    <span class="hljs-attr">fs_type:</span> <span class="hljs-string">$3</span><br>    <span class="hljs-attr">qty:</span> <span class="hljs-string">$4</span><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">match:</span> <span class="hljs-string">'*.*.jvm.*.*'</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">spark_app_jvm_memory_usage</span><br>  <span class="hljs-attr">labels:</span><br>    <span class="hljs-attr">application:</span> <span class="hljs-string">$1</span><br>    <span class="hljs-attr">executor_id:</span> <span class="hljs-string">$2</span><br>    <span class="hljs-attr">mem_type:</span> <span class="hljs-string">$3</span><br>    <span class="hljs-attr">qty:</span> <span class="hljs-string">$4</span><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">match:</span> <span class="hljs-string">'*.*.executor.jvmGCTime.count'</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">spark_app_jvm_gcTime_count</span><br>  <span class="hljs-attr">labels:</span><br>    <span class="hljs-attr">application:</span> <span class="hljs-string">$1</span><br>    <span class="hljs-attr">executor_id:</span> <span class="hljs-string">$2</span><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">match:</span> <span class="hljs-string">'*.*.jvm.pools.*.*'</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">spark_app_jvm_memory_pools</span><br>  <span class="hljs-attr">labels:</span><br>    <span class="hljs-attr">application:</span> <span class="hljs-string">$1</span><br>    <span class="hljs-attr">executor_id:</span> <span class="hljs-string">$2</span><br>    <span class="hljs-attr">mem_type:</span> <span class="hljs-string">$3</span><br>    <span class="hljs-attr">qty:</span> <span class="hljs-string">$4</span><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">match:</span> <span class="hljs-string">'*.*.executor.threadpool.*'</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">spark_app_executor_tasks</span><br>  <span class="hljs-attr">labels:</span><br>    <span class="hljs-attr">application:</span> <span class="hljs-string">$1</span><br>    <span class="hljs-attr">executor_id:</span> <span class="hljs-string">$2</span><br>    <span class="hljs-attr">qty:</span> <span class="hljs-string">$3</span><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">match:</span> <span class="hljs-string">'*.*.BlockManager.*.*'</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">spark_app_block_manager</span><br>  <span class="hljs-attr">labels:</span><br>    <span class="hljs-attr">application:</span> <span class="hljs-string">$1</span><br>    <span class="hljs-attr">executor_id:</span> <span class="hljs-string">$2</span><br>    <span class="hljs-attr">type:</span> <span class="hljs-string">$3</span><br><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">match:</span> <span class="hljs-string">'*.*.DAGScheduler.*.*'</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">spark_app_dag_scheduler</span><br>  <span class="hljs-attr">labels:</span><br>    <span class="hljs-attr">application:</span> <span class="hljs-string">$1</span><br>    <span class="hljs-attr">executor_id:</span> <span class="hljs-string">$2</span><br>    <span class="hljs-attr">type:</span> <span class="hljs-string">$3</span><br>    <span class="hljs-attr">qty:</span> <span class="hljs-string">$4</span><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">match:</span> <span class="hljs-string">'*.*.CodeGenerator.*.*'</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">spark_app_code_generator</span><br>  <span class="hljs-attr">labels:</span><br>    <span class="hljs-attr">application:</span> <span class="hljs-string">$1</span><br>    <span class="hljs-attr">executor_id:</span> <span class="hljs-string">$2</span><br>    <span class="hljs-attr">type:</span> <span class="hljs-string">$3</span><br>    <span class="hljs-attr">qty:</span> <span class="hljs-string">$4</span><br><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">match:</span> <span class="hljs-string">'*.*.HiveExternalCatalog.*.*'</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">spark_app_hive_external_catalog</span><br>  <span class="hljs-attr">labels:</span><br>    <span class="hljs-attr">application:</span> <span class="hljs-string">$1</span><br>    <span class="hljs-attr">executor_id:</span> <span class="hljs-string">$2</span><br>    <span class="hljs-attr">type:</span> <span class="hljs-string">$3</span><br>    <span class="hljs-attr">qty:</span> <span class="hljs-string">$4</span><br><br><span class="hljs-bullet">-</span> <span class="hljs-attr">match:</span> <span class="hljs-string">'*.*.*.StreamingMetrics.*.*'</span><br>  <span class="hljs-attr">name:</span> <span class="hljs-string">spark_app_streaming_metrics</span><br>  <span class="hljs-attr">labels:</span><br>    <span class="hljs-attr">application:</span> <span class="hljs-string">$1</span><br>    <span class="hljs-attr">executor_id:</span> <span class="hljs-string">$2</span><br>    <span class="hljs-attr">app_name:</span> <span class="hljs-string">$3</span><br>    <span class="hljs-attr">type:</span> <span class="hljs-string">$4</span><br>    <span class="hljs-attr">qty:</span> <span class="hljs-string">$5</span><br></code></pre></td></tr></table></figure>

<p>启动graphite_exporter</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs angelscript">nohup ./graphite_exporter --graphite.mapping-config=spark_mapping &gt;/dev/<span class="hljs-literal">null</span> <span class="hljs-number">2</span>&gt;&amp;<span class="hljs-number">1</span> &amp;<br></code></pre></td></tr></table></figure>

<p>修改prometheus配置，开启graphite_exporter</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash">vi prometheus.yml<br><br><span class="hljs-comment"># 在 scrape_configs: 中追加一下内容</span><br>  - job_name: <span class="hljs-string">'spark'</span><br>    static_configs:<br>    - targets: [<span class="hljs-string">'&lt;ip&gt;:9108'</span>] <span class="hljs-comment"># 安装graphite的服务器ip，如果不特别指定，端口默认为9108</span><br></code></pre></td></tr></table></figure>

<p>重启prometheus，点击 Status -&gt; Targets 可以看到新加的graphite<br><img src="/zzbomb/2020/08/03/202008031448-promethues-deploy/s_5.png" alt="s_5"></p>
<p>现在开始配置spark推送指标到graphite中。<br>到spark作业集群，添加metrics.properties文件</p>
<figure class="highlight dos"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs dos"><span class="hljs-built_in">cd</span> spark/submit/<span class="hljs-built_in">path</span><br>touch metrics.properties<br></code></pre></td></tr></table></figure>

<p>内容如下</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs routeros">*.sink.graphite.<span class="hljs-attribute">class</span>=org.apache.spark.metrics.sink.GraphiteSink<br>*.sink.graphite.<span class="hljs-attribute">host</span>=&lt;ip&gt; # graphite安装服务器ip<br>*.sink.graphite.<span class="hljs-attribute">port</span>=9109 # 如无指定，默认为9109<br>*.sink.graphite.<span class="hljs-attribute">period</span>=10<br>*.sink.graphite.<span class="hljs-attribute">unit</span>=seconds<br><br>master.source.jvm.<span class="hljs-attribute">class</span>=org.apache.spark.metrics.source.JvmSource<br>worker.source.jvm.<span class="hljs-attribute">class</span>=org.apache.spark.metrics.source.JvmSource<br>driver.source.jvm.<span class="hljs-attribute">class</span>=org.apache.spark.metrics.source.JvmSource<br>executor.source.jvm.<span class="hljs-attribute">class</span>=org.apache.spark.metrics.source.JvmSource<br></code></pre></td></tr></table></figure>

<p>修改启动spark作业提交脚本，添加以下配置，并重启作业</p>
<figure class="highlight dsconfig"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs dsconfig"><span class="hljs-built_in">--files</span> <span class="hljs-string">"metrics.properties"</span><br></code></pre></td></tr></table></figure>

<p>此时再到prometheus界面中，搜索spark_app_jvm_gcTime_count,可以看到数据如下<br><img src="/zzbomb/2020/08/03/202008031448-promethues-deploy/s_6.png" alt="s_6"></p>
<h2 id="Flink作业通过Prometheus监控"><a href="#Flink作业通过Prometheus监控" class="headerlink" title="Flink作业通过Prometheus监控"></a>Flink作业通过Prometheus监控</h2><p>flink默认实现了Prometheus的插件，不过需要做些小配置</p>
<p>首先将flink目录下的./opt/flink-metrics-prometheus-1.10.0.jar 丢到./lib/中，并分发到各个节点</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-built_in">cd</span> flink-1.10.0<br>cp ./opt/flink-metrics-prometheus-1.10.0.jar ./lib/<br></code></pre></td></tr></table></figure>

<p>安装PushGateway</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs bash"><span class="hljs-comment"># 下载</span><br>wget https://github.com/prometheus/pushgateway/releases/download/v1.2.0/pushgateway-1.2.0.linux-amd64.tar.gz<br><br><span class="hljs-comment"># 解压</span><br>tar -zxvf pushgateway-1.2.0.linux-amd64.tar.gz<br><br><span class="hljs-comment"># 启动</span><br><span class="hljs-built_in">cd</span> pushgateway-1.2.0.linux-amd64<br>nohup ./pushgateway --web.listen-address=:9091 &gt;/dev/null 2&gt;&amp;1 &amp;<br></code></pre></td></tr></table></figure>
<p>通过9091端口访问pushgatewayweb界面<br><img src="/zzbomb/2020/08/03/202008031448-promethues-deploy/s_2.png" alt="s_2"></p>
<p>因为还没有推送指标进来，所以在Metrics界面中暂时还没有数据</p>
<p>修改prometheus配置，开启pushgateway</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs bash">vi prometheus.yml<br><br><span class="hljs-comment"># 在 scrape_configs: 中追加一下内容</span><br>  - job_name: <span class="hljs-string">'pushgateway'</span><br>    static_configs:<br>      - targets: [<span class="hljs-string">'&lt;ip&gt;:&lt;port&gt;'</span>] <span class="hljs-comment"># 这里是指定pushgateway的ip和端口</span><br>        labels:<br>          instance: <span class="hljs-string">'pushgateway'</span><br></code></pre></td></tr></table></figure>
<p>重启prometheus，点击 Status -&gt; Targets 可以看到新加的pushgateway<br><img src="/zzbomb/2020/08/03/202008031448-promethues-deploy/s_3.png" alt="s_3"></p>
<p>现在开始配置flink推送指标到pushgateway中。</p>
<p>修改flink的配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs bash">vi conf/flink-conf.yaml<br><br><span class="hljs-comment"># 追加以下内容</span><br><br>metrics.reporter.promgateway.class: org.apache.flink.metrics.prometheus.PrometheusPushGatewayReporter<br>metrics.reporter.promgateway.host: &lt;pushgateway部署机器的IP&gt;<br>metrics.reporter.promgateway.port: 9091 <span class="hljs-comment"># 这里是指定pushgateway的端口</span><br>metrics.reporter.promgateway.jobName: flink-job<br>metrics.reporter.promgateway.randomJobNameSuffix: <span class="hljs-literal">true</span><br>metrics.reporter.promgateway.deleteOnShutdown: <span class="hljs-literal">false</span><br></code></pre></td></tr></table></figure>

<p>重启yarn-session或flink-cluster或flink-perjob，其中区别这里不赘述，请看下篇博客。</p>
<p>这时再打开prometheus的web界面，在输入框输入 flink_jobmanager_job_uptime，点击Execute，应该就有数据了<br><img src="/zzbomb/2020/08/03/202008031448-promethues-deploy/s_4.png" alt="s_4"></p>

        </div>
        
<blockquote class="copyright">
    <p><strong>本文链接 : </strong><a class="permalink" href="https://123zhangzhenbin.gitee.io/zzbomb/2020/08/03/202008031448-promethues-deploy/">https://123zhangzhenbin.gitee.io/zzbomb/2020/08/03/202008031448-promethues-deploy/</a></p>
    <p><strong>This article is available under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener noreferrer">Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)</a> License</strong></p>
</blockquote>


    </article>
    
    <section id="comments">
        
    </section>


    

</main>


<aside style="" id="sidebar" class="aside aside-fixture">
    <div class="toc-sidebar">
        <nav id="toc" class="article-toc">
            <h3 class="toc-title">文章目录</h3>
            <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Prometheus部署"><span class="toc-number">1.</span> <span class="toc-text">Prometheus部署</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Spark作业通过Prometheus监控"><span class="toc-number">2.</span> <span class="toc-text">Spark作业通过Prometheus监控</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Flink作业通过Prometheus监控"><span class="toc-number">3.</span> <span class="toc-text">Flink作业通过Prometheus监控</span></a></li></ol>
        </nav>
    </div>
</aside>





        </section>
        <footer class="hidden lg:block fixed bottom-0 left-0 sm:w-1/12 lg:w-1/6 bg-gray-100 z-40">
    
    <div class="footer-social-links">
        
            <a href="https://gitee.com/123zhangzhenbin" target="_blank" rel="noopener">
                <i class="iconfont icon-github"></i>
            </a>
        
    </div>
    
    <p style="display: block;text-align: center;font-size: 13px;"><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备16013026号</a></p>
    
        <p class="footer-custom"><a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备16013026号</a></p>
        <p class="theme-brand">Theme by <a href="https://github.com/fengkx/hexo-theme-purer" target="_blank" rel="nofollow noopener noreferrer noopener">hexo-theme-purer</a></p>

    
</footer>

        <div id="mask" class="hidden mask fixed inset-0 bg-gray-900 opacity-75 z-40"></div>
        <div id="search-view-container" class="hidden shadow-xl"></div>
        
<script src="/zzbomb/js/dom-event.min.js"></script>

<script src="//cdn.jsdelivr.net/npm/yox@1.0.0-alpha.121/dist/standard/prod/yox.min.js"></script>


<script src="/zzbomb/js/search.min.js"></script>



    <script src="//cdn.jsdelivr.net/npm/lightgallery.js@1.1.3/dist/js/lightgallery.min.js"></script>
    
<script src="/zzbomb/js/light-gallery.min.js"></script>





    </body>
</html>
